﻿#include "login.h"
#include "ui_login.h"

Login::Login(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Login)
{
    ui->setupUi(this);
    m_ptrSql = Sqlite::getIntance();
    connect(&m_register,&Register::reaback,this, &Login::show);
//    connect(ui->pb_register, &QAbstractButton::clicked, this, &Login::regi);
//    connect(&z, &zhuce::mysignal, this, &Widget::deal);
//    connect(bt, SIGNAL(clicked(bool)), this, SLOT(send_data()));

    //设置样式表

//    ui->le_name->setStyleSheet(
//                                "border-top:0px solid;"
//                                "border-left:0px solid;"
//                                "border-right:0px solid;"
//                                "border-bottom:2px solid;");/*只显示底部边框、实线*/

//    ui->le_pswd->setStyleSheet("border-top:0px solid;"
//                               "border-left:0px solid;"
//                               "border-right:0px solid;"
//                               "border-bottom:2px solid;");/*只显示底部边框、实线*/

}

Login::~Login()
{
    delete ui;
}

void Login::paintEvent(QPaintEvent *event)
{
//    Q_UNUSED(event);
    QPainter painter(this);
    painter.setOpacity(0.7);  //0.7
    QPixmap pixmap = QPixmap(":/pic/widget").scaled(this->size());// 加载背景图片
    painter.drawPixmap(this->rect(), pixmap);// 绘制背景图片
}

void Login::on_pb_login_clicked()
{
/*
    QString name = ui->le_name->text();
    QString pswd = ui->le_pswd->text();
    if(name.isEmpty() || pswd.isEmpty()){
        QMessageBox::information(nullptr, "提示" , "账号或密码错误！");
        return;
    }
    QList<User> lUser;
    lUser = m_ptrSql->getAllUser();//查询所有用户
    for(int i = 0; i < lUser.size(); ++i)
    {
        if((name == lUser[i].name) && (pswd == lUser[i].pswd))
        {
            qDebug() << "登陆成功!";
            qDebug() <<lUser[i].name <<lUser[i].pswd ;
            //成功进入主界面
            emit sendLoginSuccess();
            this->hide();
            return;
        }

    }
    QMessageBox::information(nullptr, "提示","账号或密码错误，请联系管理员!");
    return;
*/
    emit sendLoginSuccess();
    this->hide();
}

void Login::on_pb_reg_clicked()
{
   m_register.show();
   this->hide();
}
